{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "6a120475-23a6-4044-bb04-641be646f547",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "1225e9db-04a9-4b4b-8b26-312b428fbab9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3.141592653589793"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.pi"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "b98f9d41-c7f2-4580-a9ca-881138f1da77",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(10)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.array(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "893e4229-db4e-4c3e-99c2-9d0203350fa9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 2, 3])"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.array([1,2, 3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "ce7e4d45-9ee7-4ca1-971e-ceb29c913c3f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2],\n",
       "       [3, 4]])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.array([[1,2], [3,4]])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c447c6f6-2edf-4423-8a71-dbe6e271830c",
   "metadata": {},
   "source": [
    "## 数组的形状（shape）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "92aed91a-1523-44a1-8352-b37d2ddeaa47",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(2, 3)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = np.array([[1, 2, 3],\n",
    "              [4, 5, 6]])\n",
    "x.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "215849e8-57ab-4b21-8d17-252e0fa27629",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(2,)"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = np.array([1, 2])\n",
    "x.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "e081c3e5-0163-4366-9d2b-3ada002fd832",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(3,)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = np.array([2,3,4])\n",
    "x.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "7fcf3fb9-431a-4c31-84ee-ef737bbbea2c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "()"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = np.array(10)\n",
    "x.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4b9ee36f-436b-4fd8-a563-2424ed3c786c",
   "metadata": {},
   "source": [
    "## 数组形状调整，reshape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "58779211-2dc7-43d3-baf8-a6665918087b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2],\n",
       "       [3, 4],\n",
       "       [5, 6]])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = np.array([[1, 2, 3],\n",
    "              [4, 5, 6]])\n",
    "\n",
    "x.reshape(3, 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "06d6bcb3-aee7-4e28-a10b-a1cdf35243f6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 4],\n",
       "       [2, 5],\n",
       "       [3, 6]])"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x.T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "826bc52e-7e80-4e40-af8c-21f477fd9e19",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fb136b88-f599-4dd3-9094-43592d5fc8fc",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "e006d7f8-c254-4391-a1e3-84643dfcab7d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([10, 20, 30, 40])"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = np.array([10, 20, 30, 40])\n",
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e7c2ba16-d353-4346-b502-b4c7608139c7",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "adc05b2a-2c8d-4482-9694-75dc4fbcae4a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([10, 20, 30, 40, 50, 60, 70, 80])"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = np.array(range(1, 9)) * 10\n",
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "287b6be5-3b66-48d3-855e-8dc343dc4f81",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[10, 20, 30, 40, 50, 60, 70, 80]])"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = np.array(range(1, 9)) * 10\n",
    "x.reshape(1, 8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "747921fa-8f36-4b09-8891-49ec71c1656e",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "d0bbe608-0855-4223-884c-82d30c6da305",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[10],\n",
       "       [20],\n",
       "       [30],\n",
       "       [40],\n",
       "       [50],\n",
       "       [60],\n",
       "       [70],\n",
       "       [80]])"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = np.array(range(1, 9)) * 10\n",
    "x.reshape(8, 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "b6fd75dd-8cdc-47e4-b7e8-8ebb2273c155",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[10, 20],\n",
       "        [30, 40]],\n",
       "\n",
       "       [[50, 60],\n",
       "        [70, 80]]])"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = np.array(range(1, 9)) * 10\n",
    "x.reshape(2, 2, 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "db9db6c1-e7d6-4e5e-9c3b-b88e1043a2b5",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "a19a45a8-df1f-4450-a030-54378ae63b8e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[10, 20],\n",
       "       [30, 40],\n",
       "       [50, 60],\n",
       "       [70, 80]])"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = np.array(range(1, 9)) * 10\n",
    "x.reshape(4, -1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "95ecc17c-a3ca-4c4b-babe-9c8df643fc27",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "3c21d6e3-eb04-4436-899b-87063a21a5ff",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 2, 3, 4, 5, 6, 7, 8])"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.array(range(1, 9))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fcec85d5-37fc-4ba4-9be8-412689f21968",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "129e7905-399d-42f6-a860-765425997a46",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "860676f8-dc16-4123-a717-31f573a91862",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2],\n",
       "       [3, 4]])"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A = np.array([1, 2, 3, 4]).reshape(2, -1)\n",
    "A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "4560d3c0-adcd-4ec1-a071-643a887deceb",
   "metadata": {},
   "outputs": [],
   "source": [
    "x = np.array([10, 20])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "095a43c5-c8b0-4e9a-9150-0d604a44ccd3",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "e9fbfa3c-faac-40f1-9e55-d94894d915da",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "500"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x @ x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "ce7a21a6-4276-4c72-89f3-29a89b1cc6b8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 50, 110])"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A @ x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "9a58af82-b9c1-4c04-a91f-117a65cd3ec7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 70, 100])"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x @ A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0056b50b-22a8-4047-930e-3d1ba2a5526e",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "d8323a1e-0348-4f0b-bae5-c74760a511a2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 70, 100]])"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x.reshape(1, -1) @ A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "d645d4f0-6508-4e75-94ac-f4aab4128dec",
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "matmul: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (n?,k),(k,m?)->(n?,m?) (size 1 is different from 2)",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[39], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mA\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m@\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mx\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mreshape\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m-\u001b[39;49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m)\u001b[49m\n",
      "\u001b[0;31mValueError\u001b[0m: matmul: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (n?,k),(k,m?)->(n?,m?) (size 1 is different from 2)"
     ]
    }
   ],
   "source": [
    "A @ x.reshape(1, -1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "955611ae-05c6-4dbf-a837-923fa577599c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 50],\n",
       "       [110]])"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A @ x.reshape(-1, 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "3fb95a18-ac4a-46df-8ec3-67a1881219f6",
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "matmul: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (n?,k),(k,m?)->(n?,m?) (size 2 is different from 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[42], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mx\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mreshape\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m-\u001b[39;49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m@\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mA\u001b[49m\n",
      "\u001b[0;31mValueError\u001b[0m: matmul: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (n?,k),(k,m?)->(n?,m?) (size 2 is different from 1)"
     ]
    }
   ],
   "source": [
    "x.reshape(-1, 1) @ A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1b1c7c92-0623-40de-a67d-d0ff53c4a02e",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "a9f5df2d-b63d-4383-8412-a9e0245b6e52",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[10, 20, 30, 40, 50, 60, 70, 80]])"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = np.array(range(1, 9)) * 10\n",
    "x.reshape(1, -1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "b18611e8-144e-4858-ad71-8a9c5b2235be",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(3,)"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "bf629c2d-c0bf-4ac1-a18e-350323eb7b59",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[10],\n",
       "       [20],\n",
       "       [30]])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x1 = x.reshape(-1, 1)\n",
    "x1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "10dc3e9b-ecc9-4e6e-9d7b-5d6d9550ffef",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[10, 20, 30]])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x2 = x.reshape(1, -1)\n",
    "x2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "27a0265b-b66b-443a-adc8-8449cf693b14",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[100, 200, 300],\n",
       "       [200, 400, 600],\n",
       "       [300, 600, 900]])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x1 @ x2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b0e09749-e32b-474c-83d2-64e22046b348",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b0c35789-361b-41f0-9920-8c82d8b6a3d2",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "b2dd2b53-dac7-40dd-be19-61397ae8b659",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "x1 shape:  (3, 1)\n",
      "x2 shape:  (1, 3)\n"
     ]
    }
   ],
   "source": [
    "print(\"x1 shape: \", x1.shape)\n",
    "print(\"x2 shape: \", x2.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "f251b577-f9ec-404b-a701-025fd2bb6a7d",
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "cannot reshape array of size 3 into shape (2,2)",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[52], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mx\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mreshape\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m2\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m2\u001b[39;49m\u001b[43m)\u001b[49m\n",
      "\u001b[0;31mValueError\u001b[0m: cannot reshape array of size 3 into shape (2,2)"
     ]
    }
   ],
   "source": [
    "x.reshape(2, 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1fd3ec26-8f76-4766-aa12-ca1fdfaeae4d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "3d35ccc6-b0ce-47e8-b4d0-4227daf2f540",
   "metadata": {},
   "source": [
    "## 数组广播"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "382c74ff-98d6-4fec-98d9-5965709f7bd0",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "da6f197e-1f23-4107-b7d9-5244933d2222",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([11, 21, 31])"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1 + np.array([10, 20, 30])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "940d38aa-de9c-4977-b890-fd236d53a43d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([11, 21, 31])"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.array(1) + np.array([10, 20, 30])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "18e126e3-9d97-40c8-b395-b1899fe3b1eb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([11, 21, 31])"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.array([1, 1, 1]) + np.array([10, 20, 30])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5b1c321e-3b64-4707-9f57-ef2c3f1688ef",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "67dc1ff2-ccad-4d1e-85ab-880829834df4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[11, 22, 33],\n",
       "       [41, 52, 63]])"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.array([1, 2, 3])\n",
    "x = np.array([[10, 20, 30],\n",
    "              [40, 50, 60]])\n",
    "\n",
    "x + a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "b79a83f5-97c8-45e0-9a44-7d848ed446d2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[11, 22, 33],\n",
       "       [41, 52, 63]])"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.array([[1, 2, 3], [1, 2, 3]]) + x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "35dfdc3b-14b5-4c1f-9644-be4706399fcc",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "535aa2bd-263d-4c3a-a3d5-3690726597dd",
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "operands could not be broadcast together with shapes (2,3) (2,) ",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[50], line 5\u001b[0m\n\u001b[1;32m      1\u001b[0m a \u001b[38;5;241m=\u001b[39m np\u001b[38;5;241m.\u001b[39marray([\u001b[38;5;241m1\u001b[39m, \u001b[38;5;241m2\u001b[39m])\n\u001b[1;32m      2\u001b[0m x \u001b[38;5;241m=\u001b[39m np\u001b[38;5;241m.\u001b[39marray([[\u001b[38;5;241m10\u001b[39m, \u001b[38;5;241m20\u001b[39m, \u001b[38;5;241m30\u001b[39m],\n\u001b[1;32m      3\u001b[0m               [\u001b[38;5;241m40\u001b[39m, \u001b[38;5;241m50\u001b[39m, \u001b[38;5;241m60\u001b[39m]])\n\u001b[0;32m----> 5\u001b[0m \u001b[43mx\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[43ma\u001b[49m\n",
      "\u001b[0;31mValueError\u001b[0m: operands could not be broadcast together with shapes (2,3) (2,) "
     ]
    }
   ],
   "source": [
    "a = np.array([1, 2])\n",
    "x = np.array([[10, 20, 30],\n",
    "              [40, 50, 60]])\n",
    "\n",
    "x + a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "c9c99eca-d4bd-4320-a4e0-0d049578b5da",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "()"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.array(100).shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "c01ca146-859a-4e49-ba19-c2c7380003a4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[110, 120, 130],\n",
       "       [140, 150, 160]])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = np.array([[10, 20, 30],\n",
    "              [40, 50, 60]]) \n",
    "\n",
    "x + np.array(100)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
